<?php 
class Me_Acl_AclPlugin extends Zend_Controller_Plugin_Abstract
{
	protected $_acl;
	
	/**
	  * INITIALIZE
	  */
	public function __construct($acl)
	{
		$this->_acl = $acl;	
	}		
	
	public function  preDispatch( Zend_Controller_Request_Abstract $res )
	{
		$auth = Zend_Auth::getInstance();
		if( $auth.hasIdentity() )
		{
			$into = $auth->getIdentity();
			$level = $info->level;
			$role	= "";
			switch($level)
			{
				case 1: $role = "admin"; break;
				case 2: $role = "moderator"; break;
				case 3: $role = "user"; break;	
			}
			
			$controller = $res->getControllerName();
			$action = $res->getActionName();
			if( !$this->_acl->isAllow( $role, $controller, $action ))
			{
				$res->setControllerName("auth")
					->setActionName("error");	
			}
		}	
	}
}